home *** CD-ROM | disk | FTP | other *** search
/ HAM Radio 1997 / HAM Radio 1997.iso / vcls / monolog / monolog.pas < prev    next >
Pascal/Delphi Source File  |  1996-04-08  |  3KB  |  94 lines

  1. {TMonolog - A simple component for use with Monologue for WIndows}
  2. {Suggestions for improvement are appreciated - I am self taught  }
  3. {And as such some of my coding might be a bit off !              }
  4. {This component does have exception handling to try and head off }
  5. {and potential GPF's but it's been my experience that you *MUST* }
  6. {have your monologue for windows directory in your path.         }
  7. {Freeware by Derek Stutsman (dereks@metronet.com)                }
  8.  
  9. unit Monolog;
  10.  
  11. interface
  12.  
  13. uses
  14.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  15.   Forms, Dialogs;
  16.  
  17. type
  18.   TMonolog = class(TComponent)
  19.   private
  20.   glbLCB : longint;
  21.   fPitch,fSpeed : Integer;
  22.   fText : String;
  23.   procedure SayText(Speech : String);
  24.     { Private declarations }
  25.   protected
  26.     { Protected declarations }
  27.   public
  28.     { Public declarations }
  29.     constructor Create(AOwner: TComponent); override;
  30.     destructor Destroy; override;
  31.   published
  32.     { Published declarations }
  33.     property Pitch : Integer read fPitch write fPitch;
  34.     property Speed : Integer read fSpeed write fSpeed;
  35.     property Text : String read fText write SayText;
  36.   end;
  37.  
  38. procedure Register;
  39.  
  40. implementation
  41.  
  42. function OpenSpeech(HWND:Thandle;mode:Word;voicetype:Pchar) : Longint; far; external 'FB_SPCH.DLL';
  43. function Say(scb:longint;lpText:Pchar): Integer; far; external 'FB_SPCH.DLL';
  44. function Closespeech(SCB:Longint):integer; far; external 'FB_SPCH.DLL';
  45.  
  46. procedure Register;
  47. begin
  48.   RegisterComponents('Samples', [TMonolog]);
  49. end;
  50.  
  51. constructor TMonolog.Create(Aowner: TComponent);
  52. begin
  53.   inherited create(AOwner);
  54.   try
  55.   glbLCB := OpenSpeech(0,0,NIL);
  56.   fPitch := 5;
  57.   fSpeed := 5;
  58.   except
  59.   on EGPFault do application.messagebox('Monologue for Windows Error',
  60.   'Unable to start Monologue Engine.  '+#13+#10+
  61.   'Make sure your Monologue Directory is in your path.',0);
  62.   end;
  63. end;
  64.  
  65. destructor TMonolog.Destroy;
  66. begin
  67.   try
  68.   closespeech(glbLCB); 
  69.   except
  70.   on eGPFault do
  71.      begin
  72.      {Nothing, I just wanted to suppress the GP fault}
  73.      end;
  74.   end;
  75.   inherited destroy;
  76. end;
  77.  
  78. procedure TMonolog.Saytext(Speech : String);
  79. var saystring : String;
  80.     psaystring : Pchar;
  81.     ret : integer;
  82. begin
  83.  saystring := '<<~P'+inttostr(fpitch)+'S'+inttostr(fspeed)+'>>'+Speech+#0;
  84.  psaystring :=@saystring[1];
  85.  try
  86.    ret := say(glbLCB, psaystring);
  87.  except
  88.    on EGPFault do application.messagebox('Unable to say text; Monologue did not initialize','Speech Error!',0);
  89.  end;
  90. ftext := '';
  91. end;
  92.  
  93. end.
  94.